/**
 * 水库
 */
Ext.define('Admin.view.waterOptimum.resultshow.reservior',{
	extend:'Ext.panel.Panel',
	xtype:'woReservior',
	//起别名
	alias:'woReservior',
	require:[],
	user:[],
	userCLs:'big-100 small-100',
	layout: {
        type: 'vbox',
        align: 'stretch'
    },
	items: [{
		xtype: 'wohighchart',
		border: false,
		flex:1
	},{
		xtype: 'grid',
		store: {xtype:'store'},
		margin: '0 0 0 0',
		border: true,
		columns: [
			{ text: '时间', dataIndex: 'index1', minWidth: 100, width:'29%', align: 'center'},
			{ text: '洪门水库蓄变量', dataIndex: 'index2', minWidth: 100, width:'35%', align: 'center', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}
			},
			{ text: '廖坊水库蓄变量', dataIndex: 'index3', minWidth: 100, width:'35%', align: 'center', renderer:
					function customRound(value, record){
						if(value == null)return null;
						return Ext.util.Format.round(value, 3);
					}
			},
		],
		flex: 1
	}],
	getChart:function(i){
		return this.query('wohighchart')[i];
	},
	getStore: function(){
		return this.query('grid')[0].getStore();
	},
	getDataArray: function(store, index) {
		var output = new Array();
		var t = 0;
		for (var i = 0; i < store.getCount(); i++) {
			output[t] = store.getAt(i).get(index);
			t++;
		}
		return output;
	},
	displayData: function(data){
		var columns = new Array();
		columns.push({ text: '时间', dataIndex: 'index1', minWidth: 100, width:'29%', align: 'center'});
		for(var i=0;i<data.index1.length;i++){
			columns.push({ text: data.index1[i]+'水库蓄变量', dataIndex: 'index'+(i+2), minWidth: 100, width:'35%', align: 'center', renderer:
					function customRound(value, record){
					if(value == null)return null;
					return Ext.util.Format.round(value, 3);
				}
			});
		}
		this.query('grid')[0].reconfigure(null, columns);
		this.getStore().setData(data.index2);
		
		var panel = this;
		var opt1 = this.getChartOption1();
		opt1.title.text = "蓄变量变化";
		opt1.xAxis.categories = this.getDataArray(this.getStore(), 'index1');
		opt1.series = new Array();
		for(var i=0;i<data.index1.length;i++){
			opt1.series.push({
				type: 'column',
				name: data.index1[i],
				data: panel.getDataArray(this.getStore(), 'index'+(i+2))	
			});
		}
		this.getChart(0).chartDraw(opt1);
	},
	getChartOption1: function(){
		return {
		    title: {
		        text: ''
		    },
		    xAxis: {
		        categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
		    },
		    yAxis: {
		        title: {
		            text: '蓄变量m³'
		        }
		    },
		    legend: {
		    	enabled: true
		    },
		    series: [{
		    	type: 'column',
		    	name: '水位',
		        data: []
		    }]
		};
	}
});
